#include "student.h"
#include "group.h"
#include <iostream>
using namespace std;

Group::Group()
{
	*groupName = '\0';
	curNumberOfStudents = 0;
	maxNumberOfStudents = 0;
}

Group::Group(char *name, int maxNumber)
{
	strcpy(groupName, name);
	curNumberOfStudents = 0;
	maxNumberOfStudents = maxNumber;
}


Group::~Group()
{
	if (curNumberOfStudents > 0)
	{
		delete[] students;
	}
}

void Group::editGroup(char *name, int maxNumber)
{
	strcpy(groupName, name);
	if (maxNumber>curNumberOfStudents)
	{
		maxNumberOfStudents = maxNumber;
	}
}

bool Group::addStudent(char *fName, char *lName, char *fac, char *gr, char course)
{
	
	if (curNumberOfStudents > 0 && curNumberOfStudents<maxNumberOfStudents)
	{
		curNumberOfStudents++;
		Student *tmp = students;
		students = new Student[curNumberOfStudents];
		for (int i = 0; i < curNumberOfStudents; i++)
		{
			students[i] = tmp[i];
		}
		delete[] tmp;
		(students+curNumberOfStudents-1)->editStudent(fName, lName, fac, gr, course);
		return true;
	}
	else if (curNumberOfStudents == 0)
	{
		curNumberOfStudents++;
		students = new Student[curNumberOfStudents];
		(students +curNumberOfStudents - 1)->editStudent(fName, lName, fac, gr, course);
		return true;
	}
	return false;
}

void Group::showStudents()
{
	cout << endl;
	for (Student *s = students; s < students+curNumberOfStudents; s++)
	{
		cout << s-students+1 << "  ";
		cout << s->getLastName() << " " << s->getFirstName() << '\t';
		cout << s->getFaculty() << " ";
		cout << s->getStudyYear() << endl;
	}
}

